package com.kingint.web.portal.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kingint.mbg.bas.entity.BasServiceClass;
import com.kingint.mbg.bas.mapper.BasServiceClassMapper;
import com.kingint.mbg.sys.entity.UmsMember;
import com.kingint.web.portal.base.service.ServiceClassService;
import com.kingint.web.sys.service.UmsAdminService;
import com.kingint.web.util.MenuUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;


@Service
@Slf4j
public class ServiceClassServiceImpl implements ServiceClassService {
    @Resource
    private UmsAdminService adminService;
    @Resource
    private BasServiceClassMapper serviceClassMapper;

    @Override
    public List<BasServiceClass> getAllServiceClass() {
        UmsMember currentMember = adminService.getCurrentMember();
        Integer hotelId = currentMember.getHotelId();
        if (StringUtils.isEmpty(hotelId)) {
            log.debug("账号没有关联酒店id");
            return null;
        }
        QueryWrapper<BasServiceClass> wrapper = new QueryWrapper<>();
        wrapper.eq("hotel_id", hotelId)
                .eq("status", "0");
        List<BasServiceClass> list = serviceClassMapper.selectList(wrapper);
        List<BasServiceClass> parentList = null;
        if (!CollectionUtils.isEmpty(list)) {
            parentList = list.stream().filter(s -> s.getPid() == 0).collect(Collectors.toList());
            MenuUtil.cancelServiceClass(parentList, list);
        }
        return list;
    }
}
